package com.changgou.search.controller;

import com.changgou.entity.Result;
import com.changgou.entity.StatusCode;
import com.changgou.search.service.SkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author: taku
 * @CreateTime: 2020-05-10 16:59
 * @Description: ES控制器
 */
@RestController
@RequestMapping("/search")
public class SkuController {

    @Autowired
    private SkuService skuService;
    /**
     * @return
     * 将mysql的数据导入ES数据库
     */
    @GetMapping("/import")
    public Result importToEs() {
        skuService.importToEs();
        return new Result(true, StatusCode.OK, "ES数据导入成功");
    }


    /**
     * 搜索
     * @param searchMap
     * @return
     */
    @PostMapping
    public Map search(@RequestBody(required = false) Map searchMap){
        return  skuService.search(searchMap);
    }
}
